// 函数表达式       定义函数类型的时候会用到 =>
type UserFunction = (a: string, b: string) => string;
let getUserName: UserFunction = function (firstName: string, lastName: string): string {
    return firstName + lastName
};


//可选参数   ?  但是参数必须是最后一个
function print(name: string, age?: number): void {
    console.log(name, age)
}


//默认参数值
function ajax(url: string = '/user/list', method: string = 'GET') {
    console.log(url, method)
}

//如果想要使用默认值，可以给url赋值为undefined
let res = ajax(undefined,'post');

ajax('/user');

//剩余参数
function sum(prefix: string, ...numbers: number[]) {
    return prefix + numbers.reduce((acc, curr) => acc + curr, 0)
}

sum('&', 1, 2, 3);


//函数重载

function sum2(a: string, b: string): any;
function sum2(a: number, b: number): any;

function sum2(a: string | number, b: number | string) {
   console.log(a,b)
}
sum2(1,2,);
sum2('we','23');


